<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // Promise.all()方法可以等所有的Promise都执行完触发一个.then方法
        // Promise.all([Promise1,promsise2,Promise3])接收一个数组参数

        function fn1() {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    console.log('1s完成');
                    resolve()
                }, 1000)
            })
        }
        function fn2() {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    console.log('2s完成');
                    resolve()
                }, 2000)
            })
        }
        function fn3() {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    console.log('3s完成');
                    resolve()
                }, 3000)
            })
        }
        // 需要调用才能返回Promise
        Promise.all([fn1(), fn2(),fn3()]).then(()=>{
            console.log('都完成了  ----->  ');
        })
        
    </script>
</body>

</html>